<?php

namespace app\controllers\wx;

use app\controllers\Controller;
use app\controllers\wx\services\Wx;
use app\models\system\SetWx;
use app\util\Util;

/**
 * Class ShareController
 * @package app\controllers\wx
 */
class ShareController extends Controller
{
    public function actionIndex()
    {
        $url = $this->post('url');

        $timestamp = time();
        $nonce_str = Util::generateNonceString();
        $ticket = Wx::getJsapiTicket();

        $string = "jsapi_ticket={$ticket}&noncestr={$nonce_str}&timestamp={$timestamp}&url={$url}";
        $signature = sha1($string);

        $set = SetWx::getLastOne(false);
        $app_id = $set->app_id;

        return $this->successEncode([
            'appId' => $app_id,
            'timestamp' => $timestamp,
            'nonceStr' => $nonce_str,
            'signature' => $signature,
            // 'ticket' => $ticket
        ]);
    }
}